/*
 * TowerGreenOne.cs
 *
 * Created on November 24, 2007, 3:34 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * Copyright (C) 2010       Mathijs Miermans
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace HexTD
{
	public class TowerGreenOne : TowerBase
	{

		public static int price = 100;
		public static int damage = 5;
		public static float range = 4f;

		private int fireAt = -1;
		private float enemyX = 0;
		private float enemyY = 0;
		private EnemySprite enemy;
		private COLOR damageColor = COLOR.GREEN;

		/** Creates a new instance of TowerGreenOne */
		public TowerGreenOne(Game game, Context context, Hex hex)
			: base(game, TowerFactory.type.greenOne, price, damage, range)
		{
			this.lineColor = Color.Green;
			this.doInit(context, hex);
		}

		public override void doTick(int gameTime)
		{
			int enemyNr = this.findEnemy(this.fireAt, false);
			this.fireAt = enemyNr;
			if (enemyNr >= 0)
			{
				this.enemy = this.context.enemies[enemyNr];
				this.enemyX = this.enemy.getX();
				this.enemyY = this.enemy.getY();
				enemy.doDamage(this.damageCurrent, this.damageColor);
			}
		}

		public override string getStatusString()
		{
			string retString = "";
			retString += "<h1>Green Tower 1</h1>" +
					"<p>" +
					"<b>Level:</b> " + (1 + this.level) + "<br>\n" +
					"<b>Damage:</b> " + this.damageText + "<br>\n" +
					"<b>Range:</b> " + this.rangeText + "<br>" +
					"</p>\n";
			return retString;
		}

		public override string getInfoString()
		{
			string retString = "";
			retString += "<h1>Green Tower 1</h1>" +
					"<p>" +
					"Basic tower with one weak laser. Strong against green enemies, very weak against red enemies.</p>" +
					"<p>" +
					"<b>Price:</b> " + price + "<br>" +
					"<b>Damage:</b> " + this.damageCurrent + "<br>" +
					"<b>Range:</b> " + rangeCurrent + "<br>" +
					"<b>Refire rate:</b> 20/s" +
					"</p>";
			return retString;
		}

		protected override void generateShapes()
		{
#if PORT
			float width = this.context.hexPaintWidth;
			int shapeCount = 5;
			this.shapes = new Shape[shapeCount];
			this.shapes[0] = new Ellipse.Float(-0.4f * this.paintScale, -0.4f * this.paintScale, 0.8f * this.paintScale, 0.8f * this.paintScale);
			this.shapes[1] = new LineSegment.Float(0, 0.4f * paintScale, 0, paintScale);
			this.shapes[2] = new LineSegment.Float(-0.4f * width, -0.5f * 0.4f * paintScale, -width, -0.5f * paintScale);
			this.shapes[3] = new LineSegment.Float(0.4f * width, -0.5f * 0.4f * paintScale, width, -0.5f * paintScale);
			this.shapes[4] = new Ellipse.Float(-1.0f * this.context.strokeScale, -1.0f * this.context.strokeScale, 2.0f * this.context.strokeScale, 2.0f * this.context.strokeScale);

			this.shapeAction = new int[shapeCount];
			this.shapeAction[0] = 1;
			this.shapeAction[1] = 1;
			this.shapeAction[2] = 1;
			this.shapeAction[3] = 1;
			this.shapeAction[4] = 1;

			this.shapeColor = new Color[shapeCount];
			this.shapeColor[0] = this.lineColor;
			this.shapeColor[1] = this.lineColor;
			this.shapeColor[2] = this.lineColor;
			this.shapeColor[3] = this.lineColor;
			this.shapeColor[4] = this.lineColor;

			this.strokes = new Brush[shapeCount];
			this.strokes[0] = new Brush(2.0f * this.context.strokeScale, Brush.CAP_ROUND, Brush.JOIN_BEVEL);
			this.strokes[1] = this.strokes[0];
			this.strokes[2] = this.strokes[0];
			this.strokes[3] = this.strokes[0];
			this.strokes[4] = this.strokes[0];
#endif
		}

		public override void DrawEffects(GameTime gameTime)
		{
#if PORT
			Brush defaultStroke = g2.getStroke();

			if (this.fireAt > -1)
			{
				g2.setColor(this.lineColor);
				g2.draw(new LineSegment.Float(this.xPaint, this.yPaint, this.enemy.getPaintX() + ((float)(Math.random() - 0.5) * this.paintScale / 10f), this.enemy.getPaintY() + ((float)(Math.random() - 0.5) * this.paintScale / 10f)));
			}

			g2.setStroke(defaultStroke);
#endif
		}
	}
}